package ru.ifmo.filemanager.async;

import static ru.ifmo.filemanager.async.AsyncThread.numThreads;
import static ru.ifmo.filemanager.async.AsyncThread.numWaiting;
import static ru.ifmo.filemanager.async.AsyncThread.queue;

public class Async {

	private Async() { }
	
	public static void execute(Runnable runnable) {
		synchronized (queue) {
			queue.add(runnable);
			if (numWaiting == 0 && numThreads < 4) {
				new AsyncThread().start();
			} else {
				queue.notify();
			}
		}
	}
}